﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectUser2.aspx.cs" Inherits="Honestysoft.Baseframework.WebUI.Apply.SelectUser2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>选择用户</title>
    <base target="_self" />
    <script type="text/javascript" src="../Scripts/jquery-1.6.min.js"></script>
    <script language="javascript" type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <link href="../Styles/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/icon.css" rel="stylesheet" type="text/css" />   
    <link href="../Styles/control.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript" >
        $(function () {
            $('#treeOrg').tree({
                checkbox: false,
                dnd: false,
                url: '<%=Page.ResolveClientUrl("~/") %>Apply/OuInfo.ashx?Module=3&SelectTarget=<%=Request["SelectTarget"] %>&OnClick=0&randID=' + escape(new Date()), //SelectNodeType,SelectTarget
                method: "POST",
                onClick: function (node) {
                    $("#wait").css("display", "block");
                    $('#treeOrg').tree('expand', node.target);
                    $.ajax({
                        type: "POST",
                        url: '<%=Page.ResolveClientUrl("~/") %>Apply/OuInfo.ashx?Module=3&SelectTarget=<%=Request["SelectTarget"] %>&OnClick=1&ID=' + node.id + '&randID=' + escape(new Date()),
                        success: function (msg) {
                            ClearItem();
                            if (msg != "") {
                                var json = eval("(" + msg + ")");
                                for (var i = 0; i < json.length; i++) {
                                    AddItem(json[i].text, json[i].id);
                                }
                            }
                            $("#wait").css("display", "none");
                        },
                        error: function () { $("#wait").css("display", "none"); alert('服务器出错,无法获取数据！'); }
                    });
                }
            });
        });
        function ClearItem() {
            var lsb = document.getElementById("<%=lsbOu.ClientID %>");
            lsb.options.length = 0;
        }
        function AddItem(Name, Value) {
            var lsb = document.getElementById("<%=lsbOu.ClientID %>");
            if (!optionExists(lsb, Value)) {
                lsb.add(document.createElement("OPTION"));
                lsb.options[lsb.options.length - 1].text = Name;
                lsb.options[lsb.options.length - 1].value = Value;
            }
        }
    </script>
</head>
<body style="margin:4px">
    <form id="form1" runat="server">
    <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="t1" >
          <tr><th>
              选择用户
          </th></tr></table>
    <div style="float:left;width:52%;height:370px;border:1px solid #BABABA;overflow:scroll;">
        <ul id="treeOrg" style="margin:5px;"></ul>
    </div>
    <div style="float:right;width:45%">
        <table border="0" width="100%">
                <tr>
                <td align="center">  
                <asp:ListBox ID="lsbOu"  runat="server" Width=200 Height=160 Font-Size="9pt"  SelectionMode=Multiple ondblclick="Select();" >

                        </asp:ListBox>
                </td></tr>
                <tr>
                <td align=center >
                <input name="btnselectAction" id="btnselectAction" onclick="javascript:Select();" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  type=button  value="选择"/>
                <input name="btnUnSelectAction" id="btnUnSelectAction" onclick="javascript:UnSelect();"  class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'" type=button  value="删除"/> <br /><div style="height:2px;"></div>
                <input name="btnSelectALL" id="btnSelectALL" onclick="javascript:SelectALL();"  type=button value="全选"class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  />
                <input name="btnUnSelectALL" id="btnUnSelectALL" onclick="javascript:UnSelectALL();" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  type="button" value="全删" /><div style="height:2px;"></div>
                </td></tr>
                <tr>
                <td align="center">  
                <asp:ListBox ID="lsbSelected" runat="server" Width=200 Height=160   Font-Size="9pt" SelectionMode=Multiple>
                </asp:ListBox>
                </td></tr>
                </table>
    </div>
        
<table width="100%"  border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td align="center">
        
        <asp:Button ID="btnSave" Text = "确定" runat="server" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"   OnClientClick="window.returnValue=GetSelected();window.close();" />
        <asp:Button ID="btnExit" Text = "退出" runat="server" class="btn_normal" onmouseover="this.className='btn_active'" onmouseout="this.className='btn_normal'"  OnClientClick="window.close();" />
    </td>
  </tr>
</table>
<div id="wait" style="display:none;width:200px;height:50px;border:1px solid #BABABA;position:absolute;top:50px;left:360px;padding:0px;">
  <img src="../Images/loading.gif" alt='' />数据正在加载中，请稍候……
</div>
    </form>
     <script language ="javascript" type="text/javascript">
         function Select() {
             var lsb = document.getElementById("<%=lsbOu.ClientID %>");
             for (var i = 0; i < lsb.options.length; i++) {
                 if (lsb.options[i].selected) {
                     AddNoIn(lsb.options[i].text, lsb.options[i].value);
                 }
             }
         }
         function UnSelect() {
             var lsb = document.getElementById("<%=lsbSelected.ClientID %>");
             for (var i = lsb.options.length - 1; i >= 0; i--) {
                 if (lsb.options[i].selected) {
                     lsb.options.remove(i);
                 }
             }
         }
         function SelectALL() {
             var lsb = document.getElementById("<%=lsbOu.ClientID %>");
             for (var i = 0; i < lsb.options.length; i++) {
                 AddNoIn(lsb.options[i].text, lsb.options[i].value);
             }
         }
         function UnSelectALL() {
             var lsb = document.getElementById("<%=lsbSelected.ClientID %>");
             lsb.options.length = 0;
         }
         function AddNoIn(Name, Value) {
             var lsb = document.getElementById("<%=lsbSelected.ClientID %>");
             if ('<%=Request["SelectMode"]+"" %>' == '1') {
                 var arrSelected = GetSelected();
                 if (arrSelected != null && arrSelected.length == 1) {
                     alert('只能选择一个用户！');
                     return;
                 }
             }
             if (!optionExists(lsb, Value)) {
                 lsb.add(document.createElement("OPTION"));
                 lsb.options[lsb.options.length - 1].text = Name;
                 lsb.options[lsb.options.length - 1].value = Value;
             }
         }
         //检查obj列表框中是否已经存在选项opt   
         function optionExists(obj, value) {
             var length = obj.options.length;
             for (var i = 0; i < length; i++) {
                 if (obj.options[i].value == value) //如果一个选项的值和文本与给定的选项相同，则表明存在。   
                     return true;
             }
             return false; //不存在   
         }
         function UserNode() {
             var ID;
             var Name;
         }
         function GetSelected() {
             var lsb = document.getElementById("<%=lsbSelected.ClientID %>");
             if (lsb.options.length == 0) {
                 return null;
             }
             var arrSelected = new Array(lsb.options.length);
             var item = null;
             for (var i = 0; i < lsb.options.length; i++) {
                 item = new UserNode();
                 item.ID = lsb.options[i].value;
                 item.Name = lsb.options[i].text;
                 arrSelected[i] = item;
             }
             return arrSelected;
         }
         function InitData() {
             var data = window.dialogArguments;
             if (data != null) {
                 if (data.length > 0) {
                     for (var i = 0; i < data.length; i++) {
                         AddNoIn(data[i].Name, data[i].ID);
                     }
                 }
             }
         }
         if ('<%=Request["SelectMode"]+"" %>' == '3') {
             InitData();
         }
    </script> 
</body>
</html>
